import 'package:flutter/material.dart';
import 'package:flutter_juwo/common/common_index.dart';
import 'package:flutter_juwo/provider/TaskIndex.dart';
import 'package:flutter_juwo/ui/custom/judje_dialog.dart';
import 'package:flutter_juwo/ui/utils/appStatusUtils.dart';
import 'package:flutter_juwo/ui/utils/toast_utils.dart';
import 'package:flutter_juwo/ui/utils/utils.dart';
import 'package:provider/provider.dart';
import 'model/testaccount_entity.dart';
import 'task_list.dart';

class TaskPage extends StatefulWidget {
  int index;

  TaskPage(this.index);

  @override
  _TaskPageState createState() => _TaskPageState();
}

class _TaskPageState extends State<TaskPage>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  TabController _tabController;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    widget.index = Provider.of<TaskIndexModel>(context).value;
    _tabController.animateTo(Provider.of<TaskIndexModel>(context).value);

    return Scaffold(
      backgroundColor: Colors.white,
      appBar: appBar(context),
      body: new TabBarView(
        controller: _tabController,
        children: <Widget>[
          TaskList(),
          TaskList(index: 1),
          TaskList(index: 2),
          TaskList(index: 3),
          TaskList(index: 4),
        ],
      ),
    );
  }

  Widget appBar(BuildContext context) {
    return AppBar(
      title: Text(
        '任务列表',
        style: TextStyle(
            fontSize: ScreenUtil().setSp(34),
            fontFamily: Font.PingFangMedium,
            color: Colours.appC1),
      ),
      centerTitle: true,
      elevation: 0.0,
      brightness: Brightness.light,
      bottom: new TabBar(
        indicatorColor: Color(0xFFdf3033),
        indicatorWeight: ScreenUtil().setWidth(4),
        indicatorPadding: EdgeInsets.fromLTRB(18, 0, 18, 0),
        labelPadding: EdgeInsets.only(bottom: 0),
        unselectedLabelColor: Colours.appC1,
        labelColor: Color(0xFFE3393C),
        tabs: <Widget>[
          Tab(text: "全部"),
          Tab(text: "淘宝"),
          Tab(text: "京东"),
          Tab(text: "拼多多"),
          Tab(text: "浏览"),
        ],
        controller: _tabController,
      ),
    );
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController =
        new TabController(vsync: this, length: 5, initialIndex: widget.index);
/*    _tabController.addListener(() {
      Provider.of<TaskIndexModel>(context).updatePhone(_tabController.index);
    });*/

  }
}
